package com.cms.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.cms.context.constant.Constants;
import com.cms.context.utils.UtilsRedis;
import com.cms.context.utils.UtilsShiro;
import com.cms.service.api.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author laolang
 * @version 1.0.0
 * @ClassName CommonServiceImpl
 */
@Slf4j
@Service
public class CommonServiceImpl implements CommonService {



    @Autowired
    private UtilsRedis utilsRedis;


    @Override
    public String verifyImageCaptcha(String captcha) {
        String redisCaptcha = utilsRedis.get(UtilsShiro.getSession().getId() + Constants.IMAGE_CAPTCHA_SUFFIX);
       // String redisCaptcha = redisTemplate.opsForValue().get(UtilsShiro.getSession().getId() + Constants.IMAGE_CAPTCHA_SUFFIX);
        if(Objects.isNull(redisCaptcha)){
            return "验证码已失效，请重新输入！";
        }
        if(!StringUtils.equals(captcha,redisCaptcha)){
            return "验证码输入错误！请重新输入！";
        }
        return null;
    }

}
